package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/**
 * @Description NursingLevelController
 * @Author zpf
 * @Date 2024-08-27
 */
@Slf4j
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 3.1 查询所有护理等级
     */
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public List<NursingLevelVo> listAll() {
        return nursingLevelService.listAll();
    }

    /**
     * 3.2 新增护理等级
     */
    @PostMapping("/insert")
    @ApiOperation(value = "插入护理等级信息")
    public ResponseResult insert(
            @ApiParam(value = "护理等级数据", required = true)
            @RequestBody NursingLevelDto nursingLevel) {
        nursingLevelService.insert(nursingLevel);
        return ResponseResult.success();
    }

    @PostMapping("/insertBatch")
    @ApiOperation(value = "批量插入护理等级信息")
    public ResponseResult insertBatch(
            @ApiParam(value = "护理等级数据列表", required = true)
            @RequestBody List<NursingLevelDto> nursingLevelDtos) {
        nursingLevelService.insertBatch(nursingLevelDtos);
        return ResponseResult.success();
    }


    /**
     * 3.3 条件分页查询
     */
    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> getByPage(
            @ApiParam(value = "护理等级名称") String name,
            @ApiParam(value = "护理等级状态：0-禁用,1-启用") Integer status,
            @ApiParam(value = "当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量") @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        PageResponse<NursingLevelVo> nursingLevelPageInfo = nursingLevelService.getByPage(name, status, pageNum, pageSize);
        return success(nursingLevelPageInfo);
    }

    /**
     * 3.4 根据id查询护理等级
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询护理等级信息")
    public ResponseResult<NursingLevelVo> findById(
            @ApiParam(value = "护理等级ID", required = true)
            @PathVariable("id") Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }


    /**
     * 3.5 修改护理等级
     */
    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult updateNursingLevel(
            @ApiParam(value = "护理等级数据", required = true)
            @RequestBody NursingLevelDto nursingLevelDto) {
        log.info("编辑护理等级");
        nursingLevelService.updateNursingLevel(nursingLevelDto);
        return success();
    }

    /**
     * 3.6 删除
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult deleteNursingLevel(
            @ApiParam(value = "要删除的id") @PathVariable Long id) {
        log.info("删除护理项目{}", id);
        nursingLevelService.deleteNursingLevel(id);
        return success();
    }
    /**
     * 3.7 启用禁用
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult ResetStatus(
            @ApiParam(value = "要修改项目状态的id") @PathVariable Long id,
            @ApiParam(value = "状态（0：禁用，1：启用）") @PathVariable int status) {
        log.info("项目启用禁用{}-{}", id, status);
        nursingLevelService.ResetStatus(id, status);
        return success();
    }
}
